﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_hoadon_thanhtoanInfo
    {
        private int _id_lanthanhtoan;
        private int _id_hoadon;
        private DateTime _ngaythanhtoan;
        private int _nguoinhantien;
        private string _ghichu;
        private double _sotien;
        private int _lanthanhtoan;
        private int _httt;

        public cs_erp_hoadon_thanhtoanInfo()
        {
            this._id_lanthanhtoan = 0;
            this._id_hoadon = 0;
            this._ngaythanhtoan = Convert.ToDateTime("01/01/9999");
            this._nguoinhantien = 0;
            this._ghichu = " ";
            this._sotien = 0;
            this._lanthanhtoan = 0;
            this._httt = 0;
        }
        public int id_lanthanhtoan
        {
            get
            {
                return this._id_lanthanhtoan;
            }
            set
            {
                this._id_lanthanhtoan = value;
            }
        }
        public int id_hoadon
        {
            get
            {
                return this._id_hoadon;
            }
            set
            {
                this._id_hoadon = value;
            }
        }
        public DateTime ngaythanhtoan
        {
            get
            {
                return this._ngaythanhtoan;
            }
            set
            {
                this._ngaythanhtoan = value;
            }
        }
        public int nguoinhantien
        {
            get
            {
                return this._nguoinhantien;
            }
            set
            {
                this._nguoinhantien = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public double sotien
        {
            get
            {
                return this._sotien;
            }
            set
            {
                this._sotien = value;
            }
        }
        public int lanthanhtoan
        {
            get
            {
                return this._lanthanhtoan;
            }
            set
            {
                this._lanthanhtoan = value;
            }
        }

        public int httt
        {
            get
            {
                return this._httt;
            }
            set
            {
                this._httt = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[9];
            paraName[0] = "@id_lanthanhtoan";
            paraName[1] = "@id_hoadon";
            paraName[2] = "@ngaythanhtoan";
            paraName[3] = "@nguoinhantien";
            paraName[4] = "@ghichu";
            paraName[5] = "@sotien";
            paraName[6] = "@lanthanhtoan";
            paraName[7] = "@httt";
            paraName[8] = "@option";
            object[] paraValue = new object[9];
            paraValue[0] = this._id_lanthanhtoan;
            paraValue[1] = this._id_hoadon;
            paraValue[2] = this._ngaythanhtoan;
            paraValue[3] = this._nguoinhantien;
            paraValue[4] = this._ghichu;
            paraValue[5] = this._sotien;
            paraValue[6] = this._lanthanhtoan;
            paraValue[7] = this._httt;
            paraValue[8] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 9, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }


        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_HOADON_THANHTOAN", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("id_hoadon", "id_lanthanhtoan");
            cb.KetDuLieu(cbo, "ERP_HOADON_THANHTOAN", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[5];
            header[0] = "id_lanthanhtoan";
            header[1] = "id_hoadon";
            header[2] = "ngaythanhtoan";
            header[3] = "nguoinhantien";
            header[4] = "ghichu";

            string[] mappingname = new string[5];
            mappingname[0] = "id_lanthanhtoan";
            mappingname[1] = "id_hoadon";
            mappingname[2] = "ngaythanhtoan";
            mappingname[3] = "nguoinhantien";
            mappingname[4] = "ghichu";

            int[] colwidth = new int[5];
            colwidth[0] = 12;
            colwidth[1] = 12;
            colwidth[2] = 24;
            colwidth[3] = 12;
            colwidth[4] = 1500;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("ERP_HOADON_THANHTOAN", datagrid, csdl.OpenTable("ERP_HOADON_THANHTOAN", condition), header, mappingname, colwidth, 5);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HOADON_THANHTOAN", "id_lanthanhtoan = " + this._id_lanthanhtoan);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_lanthanhtoan = Convert.ToInt32(ds.Tables[0].Rows[0]["id_lanthanhtoan"].ToString().Trim());
                this._id_hoadon = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hoadon"].ToString().Trim());
                this._ngaythanhtoan = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaythanhtoan"].ToString().Trim());
                this._nguoinhantien = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhantien"].ToString().Trim());
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._sotien = Convert.ToDouble(ds.Tables[0].Rows[0]["sotien"].ToString().Trim());
                this._lanthanhtoan = Convert.ToInt32(ds.Tables[0].Rows[0]["lanthanhtoan"].ToString().Trim());
                this._httt = Convert.ToInt32(ds.Tables[0].Rows[0]["httt"].ToString().Trim());

                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public double Get_Sum()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select sum(sotien) as thanhtoan from ERP_HOADON_THANHTOAN where id_hoadon = " + this._id_hoadon;
                ds = csdl.SelecSQL(sql);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                
                return Convert.ToDouble(ds.Tables[0].Rows[0]["thanhtoan"].ToString().Trim());
            }
            catch
            {
                return -1;
            }
        }
        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_lanthanhtoan, id_hoadon, ngaythanhtoan, hoten as nguoinhantien, ghichu, sotien, lanthanhtoan "
                + " from ERP_HOADON_THANHTOAN, HMR_NHANVIEN"
                + " where id_hoadon = " + this._id_hoadon 
                + " and nguoinhantien = manhanvien order by ngaythanhtoan asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

    }
}